function diff = cevFunc(guess, c, ec, h, target, beta, chi, gamma, theta1, theta2, ebar, J, survive)

c =(1+guess)*c;
cTilde = c.^gamma.*(ec - ebar).^(1-gamma); %ctilde
utility = cTilde.^(1-theta1)/(1-theta1) - chi*h.^(1+1/theta2)/(1+1/theta2); %U(ctilde)

wel = 0; 
for  j = 1:J
    wel = beta^(j-1)*prod(survive(1:j-1))*utility(j) + wel;
end

diff = wel - target;
